﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PoolManager : MonoBehaviour {
    private static PoolManager _instance;
    public static PoolManager Instance
    {
        get
        {
            return _instance;
        }
    }
    private void Awake()
    {
        _instance = this;
        //DontDestroyOnLoad(gameObject);
    }
    Dictionary<string, Pool> pools = new Dictionary<string, Pool>();
    public void CreatPool(GameObject prefab)
    {
        Pool po = new Pool();
        po.Init(prefab);
        if (!pools.ContainsKey(prefab.name))
        {
            pools.Add(prefab.name, po);
        }
        
    }
    public GameObject Get(string name)
    {
        return pools[name].Get();
    }
    public GameObject Get(GameObject prefab)
    {
        return pools[prefab.name].Get();
    }


    public void Save(GameObject go)
    {
        go.transform.SetParent(transform, false);
        pools[go.name].Save(go);
    }
}
